function addres(ue) {
	var resname = $("#resname").val();
	var publishtime = $("#publishtime").val();
	 var newstype= $(".select_down").val();
	if(resname==""){
		alert("标题为空");
		return;
	}
	if(publishtime=="" && newstype!=4 ){
		alert("发布日期为空");
		return;
	}
	var list = $("#form").serialize();
	$.ajax({
		url : contextPath + "resource/add",
		type : "post",
		async: false,
		data : {
			data : list,
			content: ue
		},
		success : function(_data) {
			var picname = $('#rescontentlogo').val();
			$.ajax({
				url : contextPath+'admin/picture/add',
				type : 'post',
				data : {
					picname : picname
				},
				success : function(data){
					
				}
				
			});
			picname=$("#reslogo").val();
			$.ajax({
				url : contextPath+'admin/picture/add',
				type : 'post',
				data : {
					picname : picname
				},
				success : function(data){
					
				}
			});
			if(_data==1){
				alert("添加成功");
				setTimeout(location.href=contextPath+"admin/web/resource/newslist.jsp?newstype="+newstype,1000);
			}
			else{
				alert("添加失败");
			}
		}
	});

}

$(function(){
	$('#picfile').bind('change',function(){
		getPicPath();
	});
	$('#logofile').bind('change',function(){
		getLogoPath();
	});
});
function getPicPath(){
	$('#kzsx_add_pic_text').val($('#picfile').val());
}


function  updateres(ue){
	var resname = $("#resname").val();
	var publishtime = $("#publishtime").val();
    var newstype= $("#restype").val();
	if(resname==""){
		alert("标题为空");
		return;
	}
	if(publishtime=="" && newstype!=4){
		alert("发布日期为空");
		return;
	}
	var list = $("#form").serialize();
	$.ajax({
		url : contextPath + "resource/update",
		type : "post",
		async:false,
		data : {
			data : list,
			content: ue
		},
		success : function(_data) {
			var picname = $('#rescontentlogo').val();
			$.ajax({
				url : contextPath+'admin/picture/add',
				type : 'post',
				data : {
					picname : picname
				},
				success : function(data){
					
				}
			});
			picname=$("#reslogo").val();
			$.ajax({
				url : contextPath+'admin/picture/add',
				type : 'post',
				data : {
					picname : picname
				},
				success : function(data){
					
				}
			});
			if(_data==1){
				alert("修改成功");
				setTimeout(location.href=contextPath+"admin/web/resource/newslist.jsp?newstype="+newstype,1000);
			}
			else{
				alert("修改失败");
			}
		}
	});


	
	
}
function uploadPic(){
	var pic='picfile';
	var picfile=$('#'+pic).val();
	var photoType=picfile.substring(picfile.lastIndexOf("."),picfile.length).toUpperCase();
	//alert(photoType);
	if(picfile==''){
		alert('请选择图片');
		return;
	}
	if(photoType!=".JPG"&&photoType!=".GIF"){
		alert("添加的图片格式错误");
		return;
	}
	$.ajaxFileUpload({
		url : contextPath+"admin/picture/upload",
		secureuri : false,
		fileElementId : pic,
		data : {data:[$('#'+pic).attr('name')],
			devicename:picfile
		},
		dataType : 'json',
		contentType: "application/x-www-form-urlencoded; charset=utf-8",
		success : function(data,status){
			alert(data.msgDesc);
			$('#inner_box').empty();
			if(data!=null){
				//$('#inner_box').css('width',120*imgcount+'px');
				var option="";
				option += '<div class="img_p"><img class="small_pic"  src="'+basePath+'upload/'+data.resourcepicname+'" alt="" />';
				option +='<img class="img_del" onclick="imgdel(this)" src="'+basePath+'user/images/add_members_close.png" /> ';
				option +='<input type="hidden" name="rescontentlogo" id="rescontentlogo" value="'+data.resourcepicname+'"></div>';
				$('#inner_box').append(option);
			}
		}
	});
}

function getLogoPath(){
	$('#kzsx_add_logo_text').val($('#logofile').val());
}


function uploadLogo(){
	var pic='logofile';
	var picfile=$('#'+pic).val();
	var photoType=picfile.substring(picfile.lastIndexOf("."),picfile.length).toUpperCase();
	//alert(photoType);
	if(picfile==''){
		alert('请选择图片');
		return;
	}
	if(photoType!=".JPG"&&photoType!=".GIF"){
		alert("添加的图片格式错误");
		return;
	}
	$.ajaxFileUpload({
		url : contextPath+"admin/picture/logoupload",
		secureuri : false,
		fileElementId : pic,
		data : {data:[$('#'+pic).attr('name')],
			devicename:picfile
		},
		dataType : 'json',
		contentType: "application/x-www-form-urlencoded; charset=utf-8",
		success : function(data,status){
			alert(data.msgDesc);
			$('#logo_box').empty();
			if(data!=null){
				//$('#inner_box').css('width',120*imgcount+'px');
				var option="";
				option += '<div class="img_p"><img class="small_pic"  src="'+basePath+'upload/'+data.resourcepicname+'" alt="" />';
				option +='<img class="img_del" onclick="imgdel(this)" src="'+basePath+'user/images/add_members_close.png" /> ';
				option +='<input type="hidden" name="reslogo" id="reslogo" value="'+data.resourcepicname+'"></div>';
				$('#logo_box').append(option);
			}
		}
	});
}
